<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  <meta name="generator" content="Hugo 0.98.0" />

  
  <meta name="description" content="走在通往幸福的路上">
  

  
  <link rel="apple-touch-icon" sizes="180x180" href="https://blog.v5u.win/apple-touch-icon.png">

  
  <link rel="icon" type="image/png" sizes="32x32" href="https://blog.v5u.win/favicon-32x32.png">

  
  <link rel="icon" type="image/png" sizes="16x16" href="https://blog.v5u.win/favicon-16x16.png">

  
  <link rel="manifest" href="https://blog.v5u.win/site.webmanifest">

  
  <link rel="mask-icon" href="https://blog.v5u.win/safari-pinned-tab.svg" color="">

  <meta name="msapplication-TileColor" content="">

  <meta name="theme-color" content="">

  
  <link rel="stylesheet" href="https://blog.v5u.win/css/bootstrap.min.css" />

  
  <title>Flutter Dart | 为吾优</title>
  

  <style>
body {
  min-width: 300px;
}

.custom-navbar {
  margin-bottom: 1em;
  height: 60px;
}

.custom-navbar a {
  display: inline-block; 
  padding: 18px 0;
  margin-right: 1em; 
  font-weight: bold; 
}

.custom-navbar a:hover,
.custom-navbar a:focus {
  text-decoration: none; 
}

@media print {
  .custom-navbar {
    display: none;
  }
}

article {
  padding-bottom: 1em;
}

img {
  max-width: 100%;
}


body {
  background-color: #fff;
}



body {
  color: #212529;
}



a {
  color: #007bff;
}



a:hover,
a:focus {
  color: #0056b3;
}



.custom-navbar {
  background-color: #212529;
}



.custom-navbar a {
  color: rgba(255,255,255,.75);
}



.custom-navbar a:hover,
.custom-navbar a:focus {
  color: rgba(255,255,255,1);
}



.container {
  max-width: 800px;
}





</style>
</head>

<body>
  <nav class="custom-navbar">
  <div class="container">
    
    <a href="/">文章</a>
    
    <a href="/tags/">标签</a>
    
    <a href="/about/">关于</a>
    
    <a href="/index.xml">RSS</a>
    
  </div>
</nav>
  
  <div class="container">
    <article>
      <h1>Flutter Dart</h1>
<p>[TOC]</p>
<p>语法：</p>
<h2 id="关键字">关键字</h2>
<p>external 将方法的声明和实现分离 @patch(补丁)，好处是可以针对不同的平台做实现。</p>
<p>变量声明：1. 明确声明 2. 类型推导</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-dart" data-lang="dart"><span style="display:flex;"><span>main(List<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">String</span><span style="color:#f92672">&gt;</span> args) {
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 1. 明确的变量声明
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">String</span> name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;fan&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 2. 类型推导（var/final/const)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#75715e">// 2.1 var 声明变量
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">var</span> age <span style="color:#f92672">=</span> <span style="color:#ae81ff">29</span>;
</span></span><span style="display:flex;"><span>  age <span style="color:#f92672">=</span> <span style="color:#ae81ff">30</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 2.2 final 声明常量
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">final</span> forever <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;永恒&#34;</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 2.3 const 声明常量
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">const</span> jingtai <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;静态&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 2.4 final const 的区别
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#75715e">// const必须赋值 常量值（编译期间需要有一个确定的值
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#75715e">// final可以通过计算、函数获取一个值（运行期间确定一个值
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// const date1 = DateTime.now(); x
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">final</span> date1 <span style="color:#f92672">=</span> DateTime.now();
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// final p1 = Person(&#39;fan&#39;);
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#75715e">// final p2 = Person(&#39;fan&#39;);
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#75715e">// print(identical(p1, p2)); // 判断 p1 ！= p2
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 希望相同的参数看做同一个对象,严格来说不算 单例模式
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">const</span> p1 <span style="color:#f92672">=</span> Person(<span style="color:#e6db74">&#39;fan&#39;</span>); <span style="color:#75715e">// ==&gt;  const p1 = const Person(&#39;fan&#39;);
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">const</span> p2 <span style="color:#f92672">=</span> Person(<span style="color:#e6db74">&#39;fan&#39;</span>);
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">const</span> p3 <span style="color:#f92672">=</span> Person(<span style="color:#e6db74">&#39;jin&#39;</span>);
</span></span><span style="display:flex;"><span>  print(identical(p1, p2));
</span></span><span style="display:flex;"><span>  print(identical(p3, p2));
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h3 id="数据类型">数据类型</h3>
<p>// Object 和dynamic</p>
<p>// dynamic 是明确声明，和var不一样</p>
<p>// Object调用方法时，编译时会报错</p>
<p>// dynamic调用方法时，编译时不会报错，但是运行时存在安全隐患</p>
<h3 id="非零即真">非零即真</h3>
<p>在js中1或任何非null对象的值被视为true</p>
<p>在dart中，只有bool值为true被视为true</p>
<h3 id="字符串">字符串</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-dart" data-lang="dart"><span style="display:flex;"><span><span style="color:#66d9ef">var</span> str1 <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;单引号&#39;</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">var</span> str2 <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;双引号&#34;</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">var</span> str3 <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  模板
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  字符串
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  &#34;&#34;&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 字符串和表达式进行拼接，和ES6一样
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">var</span> name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;fan&#34;</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">var</span> age <span style="color:#f92672">=</span> <span style="color:#ae81ff">19</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">var</span> height <span style="color:#f92672">=</span> <span style="color:#ae81ff">1.88</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 强调：${变量} 那么{} 可以省略
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">var</span> message1 <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;my name is </span><span style="color:#e6db74">${</span>name<span style="color:#e6db74">}</span><span style="color:#e6db74">, </span><span style="color:#e6db74">$</span>age<span style="color:#e6db74">, </span><span style="color:#e6db74">$</span>height<span style="color:#e6db74">&#34;</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">var</span> message2 <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;my name is </span><span style="color:#e6db74">${</span>name<span style="color:#e6db74">}</span><span style="color:#e6db74">, </span><span style="color:#e6db74">${</span>name.runtimeType<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>;
</span></span></code></pre></div><h3 id="集合类型">集合类型</h3>
<pre tabindex="0"><code>  // 1. 列表 数组 list
  // 2. 集合 set
  // 3. 映射 对象 字典 map

  var names = [&#34;1&#34;, &#34;2&#34;, &#34;3&#34;];
  var movies = {&#34;星际穿越&#34;, &#34;xiyou&#34;, &#34;道明空间&#34;};
  var info = {&#34;name&#34;: &#34;fan&#34;, &#34;age&#34;: 18}; // key 必须可hash
</code></pre><h3 id="可选值-null-检查最佳实践">可选值 null 检查最佳实践</h3>
<pre tabindex="0"><code>bool isConnected(a,b){
	bool outConn=outgoing[a]?.contains(b) ?? false;
	bool inConn = incoming[a]?.contains(b) ?? false;
	return outConn || inConn;
}
</code></pre><p><code>?.</code>运算符在左边为null的情况下会阻断右边的调用，<code>??</code> 运算符主要作用是在左侧表达式为null时为其设置默认值。</p>
<p>对于表达式：</p>
<pre tabindex="0"><code>outgoing[a]?.contains(b)
</code></pre><p>如果outgoing为null 或 outgoing[a]为null或contains(b)的值为null，都会导致表达式为null</p>
<h2 id="function-函数是一等公民">function 函数是一等公民</h2>
<p>面向对象语言中，对象是一等公民。一等公民可以做参数，返回值，传递。</p>
<pre tabindex="0"><code>JS
function demo(){}
Dart
demo(){}

// 必选参数
// 可选参数：1. 位置可选，2. 命名可选
// 位置可选参数：[int age,double height]
// 实参和形参在进行匹配时，是根据位置的匹配
// 注意 ，只有可选参数可以有默认值
void sayHello1(String name) {
  print(name);
}

//位置可选参数
void sayHello2(String name, [int age, double height]) {
  print(name);
}

// 命名可选参数
void sayHello3(String name, {int age, double height = 0}) {
  print(name);
}
//三种函数传入方式
 // 1. 直接传方法名，对函数没有任何限制（参数，返回值）
  test(bar);
//2.  匿名函数 （参数列表){函数体}
  test(() {
    print(&#34;匿名函数被调用&#34;);
  });

  //3.  箭头函数：条件，函数体只有一行代码
  test(() =&gt; print(&#34;箭头函数被调用&#34;));
</code></pre><h2 id="运算符">运算符</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-dart" data-lang="dart"><span style="display:flex;"><span> <span style="color:#75715e">// 赋值操作 ??= 当变量有值时，??= 不执行
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 变量为null，将值赋值给变量
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">var</span> name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;fan&#34;</span>;
</span></span><span style="display:flex;"><span>  name <span style="color:#f92672">??=</span> <span style="color:#e6db74">&#34;jin&#34;</span>;
</span></span><span style="display:flex;"><span>  print(name);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// ??
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 前面变量有值，使用变量的值
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 前面变量无值，返回?? 后边的值。可以理解为三目运算符的简写
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">var</span> temp <span style="color:#f92672">=</span> name <span style="color:#f92672">??</span> <span style="color:#e6db74">&#34;is&#34;</span>;
</span></span><span style="display:flex;"><span>  print(temp);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 级联运算符
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#66d9ef">var</span> p <span style="color:#f92672">=</span> Person()
</span></span><span style="display:flex;"><span>    ..name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;ming&#34;</span>
</span></span><span style="display:flex;"><span>    ..eat()
</span></span><span style="display:flex;"><span>    ..run();
</span></span></code></pre></div><h2 id="流程控制">流程控制</h2>
<h2 id="异步编程">异步编程</h2>
<h3 id="future--promise">future == promise</h3>
<p>JS中Promise对象表示异步操作的最终完成（或失败）及其结果值，Dart中使用Future来表示异步操作。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-dart" data-lang="dart"><span style="display:flex;"><span><span style="color:#66d9ef">import</span> <span style="color:#e6db74">&#39;dart:convert&#39;</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">import</span> <span style="color:#e6db74">&#39;dart:html&#39;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>main(List<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">String</span><span style="color:#f92672">&gt;</span> args) {
</span></span><span style="display:flex;"><span>  _getIPAddress() {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">final</span> url <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;https://httpbin.org/ip&#34;</span>;
</span></span><span style="display:flex;"><span>    Future<span style="color:#f92672">&lt;</span>HttpRequest<span style="color:#f92672">&gt;</span> request <span style="color:#f92672">=</span> HttpRequest.request(url);
</span></span><span style="display:flex;"><span>    request.then((value) {
</span></span><span style="display:flex;"><span>      print(jsonDecode(value.responseText)[<span style="color:#e6db74">&#39;origin&#39;</span>]);
</span></span><span style="display:flex;"><span>    }).catchError((error) <span style="color:#f92672">=&gt;</span> print(error));
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  _getIPAddress();
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h3 id="async-和-await">async 和 await</h3>
<h2 id="类">类</h2>
<p>单继承，使用混合方式实现多继承mixin</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-dart" data-lang="dart"><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 如果用const 修饰 构造器，类也必须用 final修饰
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Person</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">final</span> <span style="color:#66d9ef">String</span> name;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">const</span> Person(<span style="color:#66d9ef">this</span>.name);
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Person</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">final</span> <span style="color:#66d9ef">String</span> name;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">final</span> <span style="color:#66d9ef">int</span> age;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 源自C++中的初始化列表
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 如下常用方式
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 这种初始化方法可以使用表达式
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 另外一种命名可选参数的初始化方式只能使用直接赋值
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  Person(<span style="color:#66d9ef">this</span>.name, {<span style="color:#66d9ef">int</span> age}) <span style="color:#f92672">:</span> <span style="color:#66d9ef">this</span>.age <span style="color:#f92672">=</span> age <span style="color:#f92672">??</span> <span style="color:#ae81ff">10</span> {}
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// Person(this.name,{int age = 10})
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>}
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Person1</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">String</span> name;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> age;
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 同名方法为构造函数
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  Person(<span style="color:#66d9ef">int</span> age, <span style="color:#66d9ef">String</span> name) {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">this</span>.age <span style="color:#f92672">=</span> age;
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">this</span>.name <span style="color:#f92672">=</span> name;
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">void</span> sayHello() {
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;my name is </span><span style="color:#e6db74">$</span>name<span style="color:#e6db74">&#34;</span>);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Eat</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">void</span> eat() {
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;eat&#34;</span>);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Sleep</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">void</span> sleep() {
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;sleeep&#34;</span>);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 抽象类 不能被实例化，通常用于架构师来设计编码格式
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">abstract</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Animal</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">void</span> run(); <span style="color:#75715e">// 抽象方法
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  <span style="color:#75715e">// 抽象类的用处：我有一个想法，但是不知道怎么实现，提醒继承者去实现
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// 多继承 混合
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Person2</span> <span style="color:#66d9ef">extends</span> Animal <span style="color:#66d9ef">with</span> Eat, Sleep {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">String</span> name;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> age;
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 同名方法为构造函数
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>  Person2(<span style="color:#66d9ef">int</span> age, <span style="color:#66d9ef">String</span> name) {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">this</span>.age <span style="color:#f92672">=</span> age;
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">this</span>.name <span style="color:#f92672">=</span> name;
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">void</span> sayHello() {
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;my name is </span><span style="color:#e6db74">$</span>name<span style="color:#e6db74">&#34;</span>);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">@</span>override
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">void</span> run() {
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;haha run&#34;</span>);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>混合的菱形继承问题：编译后，最近原则调用方法。先找自身的，再找with后面，从后往前以此调用。</p>
<h3 id="多核cpu的利用">多核CPU的利用</h3>
<p>Isolate概念 隔离
Dart是单线程的，线程所在的空间被称为Isolate。比如Flutter中有一个Root
Isolate，负责运行Flutter代码，例如UI渲染，用户交互等。
在Isolate中，资源隔离做的非常好，每个Isolate有自己的Event Loop和Queue。</p>
<ul>
<li>Isolate之间不共享任何资源，只能依靠消息机制通信，因此也就没有资源抢占问题。
这不就是多进程方案！</li>
</ul>

    </article>
  </div>

  
  
  

  
</body>

</html>